package com.edgclub.edg.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.edgclub.edg.R;
import com.edgclub.edg.adapter.adapteruitls.GzBaseAdapter;
import com.edgclub.edg.adapter.adapteruitls.MyItemClickListener;
import com.edgclub.edg.adapter.adapteruitls.MyItemLongClickListener;
import com.edgclub.edg.adapter.adapteruitls.RViewHolder;
import com.edgclub.edg.model.VideoBean;
import com.edgclub.edg.uc.UnableScrollGridView;
import com.edgclub.edg.utils.GlideUtil.GlideUtils;

import java.util.ArrayList;

/**
 */
public class FindVideoAdapter extends GzBaseAdapter{
    private ArrayList<VideoBean> datas = null;
    private Context mContext;
    private GlideUtils glideUtils;


    public FindVideoAdapter(Context context) {
        this.mContext = context;
        glideUtils = new GlideUtils();

    }

    //创建新View，被LayoutManager所调用
    @Override
    public FindVideoAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_find_video,viewGroup,false);
        ViewHolder vh = new ViewHolder(view,mListener,mLongClickListener);
        return vh;
    }

    //将数据与界面进行绑定的操作
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder1, final int position) {
        FindVideoAdapter.ViewHolder viewHolder= (ViewHolder) viewHolder1;
        final VideoBean videoBean = datas.get(position);
        viewHolder.tv_name.setText(videoBean.getName()+"");
        glideUtils.Glidde_loadImage(mContext,videoBean.getLogo(),viewHolder.logo);
        viewHolder.unableScrollGridView.setVisibility(View.GONE);
//        if(videoBean.getVideos()!=null && videoBean.getVideos().size()>0){
//            viewHolder.unableScrollGridView.setVisibility(View.VISIBLE);
//            FindVideoGridViewAdapter gridViewAdapter = new FindVideoGridViewAdapter(mContext);
//            gridViewAdapter.setDatas(videoBean.getVideos());
//            viewHolder.unableScrollGridView.setAdapter(gridViewAdapter);
//            gridViewAdapter.notifyDataSetChanged();
//        }

    }


    //获取数据的数量
    @Override
    public int getItemCount() {
        if(datas==null)return 0;
        return datas.size();
    }

    public ArrayList<VideoBean> getDatas() {
        return datas;
    }

    public void setDatas(ArrayList<VideoBean> datas) {
        this.datas = datas;
    }

    public void jumpTopicDetailActivity(int position){
//        Intent intent = new Intent(mContext, GzTopicDetailActivity.class);
//        intent.putExtra("topicId", datas.get(position).getPostsId());
//        mContext.startActivity(intent);
//        ((Activity)mContext).overridePendingTransition(R.anim.slide_in_from_right,
//                R.anim.slide_out_to_left);
    }

    //自定义的ViewHolder，持有每个Item的的所有界面元素
    public static class ViewHolder extends RViewHolder {
        private UnableScrollGridView unableScrollGridView;
        private ImageView logo;
        private TextView tv_name,more;

        public ViewHolder(View view, MyItemClickListener mListener, MyItemLongClickListener mLongClickListener){
            super(view,mListener,mLongClickListener);
            unableScrollGridView = (UnableScrollGridView) view.findViewById(R.id.unableScrollGridView);
            logo = (ImageView) view.findViewById(R.id.logo);
            tv_name = (TextView) view.findViewById(R.id.tv_name);
            more = (TextView) view.findViewById(R.id.more);
        }
    }

}
